package com.thunisoft.proxy.cglib;

import java.lang.reflect.Method;

import com.thunisoft.proxy.impl.CglibTest;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * @title CglibProxyTest.java
 * @package com.thunisoft.proxy.cglib
 * @projectName spring.boot
 * @author yzj 
 * @date 2019年6月12日 下午5:54:06
 */
public class CglibProxyTest implements MethodInterceptor {
    
    private CglibProxyTest() {
    }
    
    public static <T extends CglibTest> CglibTest newProxyInstance(Class<T> targetInstanceClazz){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(targetInstanceClazz);
        enhancer.setCallback(new CglibProxyTest());
        return (CglibTest) enhancer.create();
    }

    public Object intercept(Object obj, Method method, Object[] args,
            MethodProxy proxy) throws Throwable {
    	System.out.println("测试cglib代理");
        return proxy.invokeSuper(obj, args);
    }

}
